//雇主详情完善信息
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:get/get.dart';
import 'package:get/get_core/src/get_main.dart';
import 'package:untitled1/app/res/myColors.dart';
import 'package:untitled1/app/utils/utilDialog.dart';
import 'package:untitled1/app/widgets/TitleBar.dart';
import 'package:untitled1/app/widgets/base_page/BaseStatefulPage.dart';


import '../../../utils/utilScreen.dart';
import '../../../widgets/TextSelector.dart';
import 'ServeBasicInfoUpdateController.dart';
import 'ServeJobUpdateController.dart';

//基本信息
class ServeBasicInfoUpdate extends BaseStatefulPage {
  @override
  BaseStatefulPageState<BaseStatefulPage> createState() {
    return _ServeDetailUpdateState();
  }
}

class _ServeDetailUpdateState  extends BaseStatefulPageState<ServeBasicInfoUpdate> {
  final ServeBasicInfoUpdateController controllerData = Get.put(
    ServeBasicInfoUpdateController(),
  );


  var gender = '';

  @override
  Widget buildPage(BuildContext context) {
    return Scaffold(
      appBar: TitleBar(title: "基本信息"),
      body: Container(
        color: myColors.c_bg,
        child: Column(
          children: [
            Expanded(
              child: SingleChildScrollView(
                child: Column(
                  children: [
                    buildTitle('基本信息'),
                    Divider(height: 1, color: myColors.c_divider),
                    buildItemTextField2('姓名', controllerData.xingming,isRequired:true) ,
                    Divider(height: 1, color: myColors.c_divider),
                    buildItemTextField2('手机号', controllerData.shoujiaho,isRequired:true) ,
                    Divider(height: 1, color: myColors.c_divider),
                    buildItemTextField2('自我介绍', controllerData.ziwojieshao,isRequired:true) ,
                    Divider(height: 1, color: myColors.c_divider),
                    buildItemTextField2('工作年限(年)', controllerData.gognzuonianxian) ,
                    Divider(height: 1, color: myColors.c_divider),
                    buildItemTextField2('家政经验(年)', controllerData.gognzuonianxian,isRequired:true) ,
                    Divider(height: 1, color: myColors.c_divider),
                    buildItem(
                      '出生日期',
                      controllerData.chushengriq,
                      isRequired: true,
                      onTapFunction: () {
                        controllerData.chushengriq.value = '男';
                      },
                    ),
                    Divider(height: 1, color: myColors.c_divider),
                    buildItem(
                      '性别',
                      controllerData.xingbie,
                      isRequired: true,
                      onTapFunction: () {
                        controllerData.xingbie.value = '男';
                      },
                    ),

                    Divider(height: 1, color: myColors.c_divider),
                    buildItem(
                      '籍贯',
                      controllerData.jiguan,
                      isRequired: true,
                      onTapFunction: () {
                        controllerData.jiguan.value = '男';
                      },
                    ),
                    Divider(height: 1, color: myColors.c_divider),
                    buildItem(
                      '学历',
                      controllerData.xueli,
                      isRequired: false,
                      onTapFunction: () {
                        controllerData.xueli.value = '男';
                      },
                    ),
                    Divider(height: 1, color: myColors.c_divider),
                    buildItem(
                      '属相',
                      controllerData.shuxiang,
                      isRequired: false,
                      onTapFunction: () {
                        controllerData.shuxiang.value = '男';
                      },
                    ),
                    Divider(height: 1, color: myColors.c_divider),
                    buildItem(
                      '星座',
                      controllerData.xingzuo,
                      isRequired: false,
                      onTapFunction: () {
                        controllerData.xingzuo.value = '男';
                      },
                    ),

                    Divider(height: 1, color: myColors.c_divider),
                    buildItemTextField2("身高", controllerData.shengao),
                    Divider(height: 1, color: myColors.c_divider),
                    buildItem(
                      '民族',
                      controllerData.minzu,
                      isRequired: false,
                      onTapFunction: () {
                        controllerData.minzu.value = '男';
                      },
                    ),
                    Divider(height: 1, color: myColors.c_divider),
                    buildItem(
                      '宗教信仰',
                      controllerData.zongjiaoxinyang,
                      isRequired: false,
                      onTapFunction: () {
                        controllerData.zongjiaoxinyang.value = '男';
                      },
                    ),
                    Divider(height: 1, color: myColors.c_divider),
                    buildItem(
                      '地址',
                      controllerData.dizhi,
                      isRequired: false,
                      onTapFunction: () {
                        controllerData.dizhi.value = '男';
                      },
                    ),
                    Divider(height: 1, color: myColors.c_divider),
                    buildItemTextField2("详细地址", controllerData.xinagxidizhi),
                    Divider(height: 1, color: myColors.c_divider),
                    buildItem(
                      '档期时间',
                      controllerData.dangqishijian,
                      isRequired: true,
                      onTapFunction: () {
                        controllerData.dangqishijian.value = '男';
                      },
                    ),
                    Divider(height: 1, color: myColors.c_divider),
                    buildItem(
                      '服务雇主数',
                      controllerData.dangqishijian,
                      isRequired: true,
                      onTapFunction: () {
                        controllerData.dangqishijian.value = '男';
                      },
                    ),

                    Divider(height: 1, color: myColors.c_divider),
                    buildItem(
                      '语言',
                      controllerData.yuyan,
                      isRequired: true,
                      onTapFunction: () {
                        controllerData.yuyan.value = '男';
                      },
                    ),


                  ],
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }

  // 头像组件
  Widget buildTitle(String title) {
    return Container(
      alignment: Alignment.centerLeft,
      height: 40,
      margin: const EdgeInsets.symmetric(horizontal: 15),
      child: Text(
        title,
        style: TextStyle(color: myColors.c_191919, fontWeight: FontWeight.bold),
      ),
    );
  }

  // 通用信息项
  Widget buildItem(
    String title,
    RxString value, {
    bool showArrow = true,
    int maxLines = 1,
    bool isRequired = false, Color bgcolor = Colors.white,
    Function()? onTapFunction,
  }) {
    return Obx(
      () => Container(
        height: 40,
        color:bgcolor,
        padding: const EdgeInsets.only(left: 15, right: 15),
        child:Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Row(
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                if (isRequired)
                  Text(
                    "*",
                    style: TextStyle(
                      color: Colors.red,
                      fontSize: 12,
                      fontWeight: FontWeight.bold,
                    ),
                  ),
                Text(
                  "${title}:",
                  style: const TextStyle(fontSize: 14, color: myColors.c_191919),
                ),
              ],
            ),
            Expanded(child: InkWell(
              onTap: () {
                if (onTapFunction == null) {
                  return;
                }
                // setState(() {
                onTapFunction();
                print('>]aaaaaaa  value=${value}');
                // });
              },
              child: Container(
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.end,
                  children: [
                    if (value.value != null)
                      Text(
                        value.value,
                        maxLines: maxLines,
                        overflow: TextOverflow.ellipsis,
                        style: const TextStyle(color: Colors.black),
                      ),
                    if (showArrow) const SizedBox(width: 10),
                    if (showArrow) const Icon(Icons.arrow_forward_ios, size: 16),
                  ],
                ),
              ),
              ))
          ],
        )
      ),
    );
  }
  Widget buildItemTextField2(String title, RxString value,{bool isRequired = false}) {
    final TextEditingController _controller = TextEditingController(text: value.value);
    return Container(
      color: myColors.white,
      height: 40,
      padding: EdgeInsets.only(left: 15, right: 15),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          if (isRequired)Text(
              "*",
              style: TextStyle(
                color: Colors.red,
                fontSize: 12,
                fontWeight: FontWeight.bold,
              ),
            ),
          Text(
            "${title}：",
            style: const TextStyle(fontSize: 14, color: myColors.c_191919),
          ),
          Expanded(
            child: TextField(
              controller: _controller, // 控制器绑定
              textAlign: TextAlign.right,
              //字体样式
              style: TextStyle(fontSize: 14, color: myColors.c_191919),
              maxLines: 1, // 显示1行，null：自动换行
              decoration: InputDecoration(
                hintText: '请输入内容', // 设置提示语
                border: InputBorder.none, // 移除所有边框
                //把边距都设置0
                contentPadding:EdgeInsets.symmetric(vertical: 0, horizontal: 0),
                filled: false,//显示填充颜色
                isDense: true, //（上下居中） 紧凑模式，防止多余的内边距
              ),
              onChanged: (text) {
                value.value=text;
              },
            ),
          ),
        ],
      ),
    );
  }
  Widget buildItemTextField(String title, RxString value) {
    final TextEditingController _controller = TextEditingController(text: value.value);
    return Container(
      color: myColors.white,
      padding: EdgeInsets.only(left: 15, right: 15, top: 10, bottom: 10),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            title,
            style: const TextStyle(fontSize: 14, color: myColors.c_191919),
          ),
          SizedBox(
            height: 60,
            width: utilScreen.getScreenWidth(context),
            child: TextField(
              controller: _controller, // 控制器绑定
              style: TextStyle(fontSize: 14, color: myColors.c_191919),
              maxLines: null, // 没有限制行数 → 自动换行
              decoration: InputDecoration(
                hintText: '请输入内容', // 设置提示语
                border: InputBorder.none, // 移除所有边框
              ),
              onChanged: (text) {
                value.value=text;
              },
            ),
          ),
        ],
      ),
    );
  }
}
